package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fly.domain.Notice;
import com.ruoyi.fly.domain.vo.NoticeVo;
import com.ruoyi.fly.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
@Api(tags = "通知管理")
public class NoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 查询通知列表
     *
     * @param notice
     * @return
     */
    @ApiOperation(value = "查询通知列表")
    @PostMapping("/list")
    public TableDataInfo list(Notice notice) {
        startPage();
        List<Notice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据id查询通知
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询通知")
    @GetMapping(value = "/selNoticeById/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(noticeService.selectNoticeById(id));
    }

    /**
     * 新增通知
     * @param noticeVo
     * @return
     */
    @ApiOperation(value = "新增通知")
    @PostMapping("/addNotice")
    public R add(@RequestBody NoticeVo noticeVo) {
        return noticeService.insertNotice(noticeVo);
    }

    /**
     * 修改通知
     * @param noticeVo
     * @return
     */
    @ApiOperation(value = "修改通知")
    @PostMapping("/editNotice")
    public R edit(@RequestBody NoticeVo noticeVo) {
        return noticeService.updateNotice(noticeVo);
    }

    /**
     * 删除通知
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除通知")
    @PostMapping("/deleteNoticeById/{ids}")
    public R remove(@PathVariable String[] ids) {
        return noticeService.deleteNoticeByIds(ids);
    }
}
